package org.practice.action;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.practice.dao.UserDao;
import org.practice.model.User;
import org.practice.util.ShopDaoFactory;


@SuppressWarnings("serial")
public class RegisterOneAction extends BaseAction {
	private static final Logger logger = Logger.getLogger(RegisterOneAction.class);
	private User user = new User();
	@Override
	public String execute() throws Exception {
		//ImageCreateServlet 设置session.setAttribute("number", number);
		String number = (String)getSession().getAttribute("number");
		if(StringUtils.isNotBlank(user.getVerifyCode())&&number.equals(user.getVerifyCode())){
			UserDao userDao = ShopDaoFactory.createUserDao();
			userDao.addUser(user);
			// send info to user-email
			logger.info("email:" + user.getVerifyCode() + "-" + user.getId());
			return SUCCESS;
		}else {
			this.addActionError(getText("error.verify.number"));
			return FAIL;
		}
	}
	
	public String registerForm(){
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	

}
